#include "EditorDebugConsoleViewModel.h"

#include "Asset/EditorDefaultPackage.h"

void REditorDebugConsoleViewModel::BindModel(TSharedObjectPtr<REditorAbilityModel> InModel)
{
    Super::BindModel(InModel);

    OutputModel = InModel;

    Icon = REditorDefaultPackage::Get()->GetIcon(U"CodiconDebugConsole");
    HighlightIcon = REditorDefaultPackage::Get()->GetIcon(U"CodiconDebugConsole_Highlight");
    ClearAllIcon= REditorDefaultPackage::Get()->GetIcon(U"CodiconClearAll");

    OutputModel->OnLineNumChanged.Bind([this]()
    {
        OnLineNumChanged.ExecuteIfBound();
    });
}

TSharedObjectPtr<RTexture2D> REditorDebugConsoleViewModel::GetIcon() const
{
    return Icon;
}

TSharedObjectPtr<RTexture2D> REditorDebugConsoleViewModel::GetHighlightIcon() const
{
    return HighlightIcon;
}

void REditorDebugConsoleViewModel::ClearLines()
{
    OutputModel->ClearLines();
}

int64_t REditorDebugConsoleViewModel::GetLineNum() const
{
    return OutputModel->GetLineNum();
}

const CString &REditorDebugConsoleViewModel::GetLine(int64_t InIndex)
{
    return OutputModel->GetLine(InIndex).Content;
}

SColor REditorDebugConsoleViewModel::GetLineColor(int64_t InIndex)
{
    static SColor Colors[2] = { 
        SColor::Yellow,
        SColor::Blue
    };
    return Colors[(int32_t)OutputModel->GetLine(InIndex).LineType];
}

void REditorDebugConsoleViewModel::ClearAll()
{
    OutputModel->ClearLines();
}
